home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / +system+ / tools / gui / bgui.lha / bgui / Examples / Source / FileRequester.c < prev    next >
C/C++ Source or Header  |  2000-02-27  |  7KB  |  173 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/Attic/FileRequester.c,v 1.1.2.1 1998/02/28 17:45:16 mlemos Exp $
  3.  *
  4.  * FileRequester.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1995 Jaba Development.
  8.  * (C) Copyright 1995 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  * $Log: FileRequester.c,v $
  12.  * Revision 1.1.2.1  1998/02/28 17:45:16  mlemos
  13.  * Ian sources
  14.  *
  15.  *
  16.  */
  17.  
  18. /* Execute me to compile with DICE V3.0.
  19. dcc FileRequester.c -proto -mi -ms -mRR -3.0 -lbgui
  20. quit
  21. */
  22.  
  23. #include "DemoCode.h"
  24.  
  25. #include <libraries/asl.h>
  26. #include <proto/utility.h>
  27.  
  28. /*
  29. **      Bulk GetAttr(). This really belongs in amiga.lib... I think.
  30. **/
  31. ULONG GetAttrs( Object *obj, ULONG tag1, ... )
  32. {
  33.         struct TagItem          *tstate = ( struct TagItem * )&tag1, *tag;
  34.         ULONG                    num = 0L;
  35.  
  36.         while ( tag = NextTagItem( &tstate ))
  37.                 num += GetAttr( tag->ti_Tag, obj, ( ULONG * )tag->ti_Data );
  38.  
  39.         return( num );
  40. }
  41.  
  42. /*
  43. **      Put up a simple requester.
  44. **/
  45. ULONG Req( UBYTE *gadgets, UBYTE *body, ... )
  46. {
  47.         struct bguiRequest      req = { NULL };
  48.  
  49.         req.br_GadgetFormat     = gadgets;
  50.         req.br_TextFormat       = body;
  51.         req.br_Flags            = BREQF_AUTO_ASPECT;
  52.         req.br_Underscore       = '_';
  53.  
  54.         return( BGUI_RequestA( NULL, &req, ( ULONG * )( &body + 1 )));
  55. }
  56.  
  57. VOID StartDemo( void )
  58. {
  59.         Object          *filereq;
  60.         ULONG            rc, dr, fl, pt, pa, l, t, w, h;
  61.  
  62.         /*
  63.         **      Present a simple requester.
  64.         **
  65.         **      NOTE: For some reason the size of the requester is not
  66.         **            saved when RTPatch (from reqtools) is active. When
  67.         **            I have some time left I'll take a look and try to
  68.         **            find out why.
  69.         **/
  70.         if ( ! Req( "_Continue|_Go Away!", ISEQ_C "This demo shows you how to use the BGUI\n"
  71.                                            "BOOPSI ASL interface. It pops a simple Load requester\n"
  72.                                            "and let's you play with it. After this the requester\n"
  73.                                            "type is changed into a Save requester. Ofcourse the\n"
  74.                                            "current path, requester size and position etc. is saved\n"
  75.                                            "while the object remains valid." ))
  76.                 return;
  77.         /*
  78.         **      Create a filerequester object.
  79.         **/
  80.         filereq = FileReqObject, ASLFR_DoPatterns, TRUE, EndObject;
  81.  
  82.         /*
  83.         **      Object OK?
  84.         **/
  85.         if ( filereq ) {
  86.                 /*
  87.                 **      Pop the requester.
  88.                 **/
  89.                 if ( ! ( rc = DoRequest( filereq ))) {
  90.                         /*
  91.                         **      Obtain attribute values.
  92.                         **/
  93.                         GetAttrs( filereq, FRQ_Drawer,          &dr,
  94.                                            FRQ_File,            &fl,
  95.                                            FRQ_Pattern,         &pt,
  96.                                            FRQ_Path,            &pa,
  97.                                            FRQ_Left,            &l,
  98.                                            FRQ_Top,             &t,
  99.                                            FRQ_Width,           &w,
  100.                                            FRQ_Height,          &h,
  101.                                            TAG_END );
  102.                         /*
  103.                         **      Dump 'm on the console.
  104.                         **/
  105.                         Tell( "Drawer                : %s\n"
  106.                               "File                  : %s\n"
  107.                               "Pattern               : %s\n"
  108.                               "Path                  : %s\n"
  109.                               "Left,Top,Width,Height : %ld,%ld,%ld,%ld\n",
  110.                               dr, fl, pt, pa, l, t, w, h );
  111.                 } else if ( rc == FRQ_CANCEL )
  112.                         /*
  113.                         **      Requester canceled.
  114.                         **/
  115.                         Tell("Canceled\n" );
  116.                 else
  117.                         /*
  118.                         **      Error.
  119.                         **/
  120.                         Tell("Error %ld\n", rc );
  121.  
  122.                 /*
  123.                 **      Make it a save requester.
  124.                 **/
  125.                 if ( ! ( rc = SetAttrs( filereq, ASLFR_DoSaveMode, TRUE, TAG_END ))) {
  126.                         /*
  127.                         **      Pop the requester.
  128.                         **/
  129.                         if ( ! ( rc = DoRequest( filereq ))) {
  130.                                 /*
  131.                                 **      Obtain attribute values.
  132.                                 **/
  133.                                 GetAttrs( filereq, FRQ_Drawer,          &dr,
  134.                                                    FRQ_File,            &fl,
  135.                                                    FRQ_Pattern,         &pt,
  136.                                                    FRQ_Path,            &pa,
  137.                                                    FRQ_Left,            &l,
  138.                                                    FRQ_Top,             &t,
  139.                                                    FRQ_Width,           &w,
  140.                                                    FRQ_Height,          &h,
  141.                                                    TAG_END );
  142.                                 /*
  143.                                 **      Dump 'm to the console.
  144.                                 **/
  145.                                 Tell( "Drawer                : %s\n"
  146.                                       "File                  : %s\n"
  147.                                       "Pattern               : %s\n"
  148.                                       "Path                  : %s\n"
  149.                                       "Left,Top,Width,Height : %ld,%ld,%ld,%ld\n",
  150.                                       dr, fl, pt, pa, l, t, w, h );
  151.                         } else if ( rc == FRQ_CANCEL )
  152.                                 /*
  153.                                 **      Requester canceled.
  154.                                 **/
  155.                                 Tell("Canceled\n" );
  156.                         else
  157.                                 /*
  158.                                 **      Error.
  159.                                 **/
  160.                                 Tell("Error %ld\n", rc );
  161.                 } else
  162.                         /*
  163.                         **      Error with SetAttrs().
  164.                         **/
  165.                         Tell( "Error %ld\n", rc );
  166.                 /*
  167.                 **      Dump the filerequester object.
  168.                 **/
  169.                 DisposeObject( filereq);
  170.         } else
  171.                 Tell( "unable to create filerequester object.\n" );
  172. }
  173.